package edu.ciee.tz.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

import edu.ciee.tz.dao.UserDAO;
import edu.ciee.tz.dao.ZhibieDAO;
import edu.ciee.tz.dao.LaiyuanDAO;
import edu.ciee.tz.model.User;

@Component("user")
@Scope("prototype")
public class LoginAction extends ActionSupport {
	
	private UserDAO userDao;
	
	private int id;
	private String username;
	private String password;
	
	private String tip;
	
	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	private ZhibieDAO zhibieDAO;	
	public LaiyuanDAO getLaiyuanDAO() {
		return laiyuanDAO;
	}
	@Resource
	public void setLaiyuanDAO(LaiyuanDAO laiyuanDAO) {
		this.laiyuanDAO = laiyuanDAO;
	}

	private LaiyuanDAO laiyuanDAO;
	
	public ZhibieDAO getZhibieDAO() {
		return zhibieDAO;
	}
	
	@Resource
	public void setZhibieDAO(ZhibieDAO zhibieDAO) {
		this.zhibieDAO = zhibieDAO;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}


	public UserDAO getUserDao() {
		return userDao;
	}
	@Resource
	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}

	public String verify() throws Exception {
	
		User u = new User();
		u.setName(this.getUsername());		
		u.setPassword(this.getPassword());
		if(userDao.checkPermission(u)) {
			return "success";
		}else
		return "error";
	}
	
	public String execute(){
		try{			
			this.getZhibieDAO().searchAll();
			this.getLaiyuanDAO().searchAll();
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			System.out.println("error");
			return "error";
		}
	}
	
}
